{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Matplotlib配色功能详解01_基础篇](https://blog.csdn.net/sinat_32570141/article/details/104834137)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import math\n",
    "import numpy as np\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "plt.axes()\n",
    "x = np.arange(0, 2*math.pi, 0.001)\n",
    "y = np.sin(x)\n",
    "plt.plot(x,y,color=(0.7,0.2,0.3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "plt.axes()\n",
    "x = np.arange(0, 2*math.pi, 0.001)\n",
    "y = np.sin(x)\n",
    "plt.plot(x,y,color='#FF7F0E')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "plt.axes()\n",
    "x = np.arange(0, 2*math.pi, 0.001)\n",
    "y = np.sin(x)\n",
    "plt.plot(x,y,color='#F4F')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "plt.axes()\n",
    "x = np.arange(0, 2*math.pi, 0.001)\n",
    "y = np.sin(x)\n",
    "plt.plot(x,y,color='0.5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "plt.axes()\n",
    "x = np.arange(0, 2*math.pi, 0.001)\n",
    "y = np.sin(x)\n",
    "plt.plot(x,y,color='c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "plt.axes()\n",
    "x = np.arange(0, 2*math.pi, 0.001)\n",
    "y = np.sin(x)\n",
    "plt.plot(x,y,color='C7')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mpl.colors.XKCD_COLORS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "[name for name in dir(mpl.colors) if 'COLORS' in name]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mpl.colors.TABLEAU_COLORS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mpl.rcParams['axes.prop_cycle']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[matplotlib 配色之内置 colormap](https://blog.csdn.net/sinat_32570141/article/details/105356507)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import math\n",
    "import numpy as np\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "t = np.arange(0.0,2.0,0.01)\n",
    "s = np.sin(2*np.pi*t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "upper = 0.77\n",
    "lower = -0.77\n",
    "\n",
    "supper = np.ma.masked_where(s<upper,s)\n",
    "slower = np.ma.masked_where(s>lower,s)\n",
    "smiddle = np.ma.masked_where( (s<lower) | (s>upper),s)\n",
    "\n",
    "fig,ax = plt.subplots()\n",
    "ax.plot(t, smiddle, t, slower, t, supper)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "upper = 0.75\n",
    "lower = 1.75\n",
    "\n",
    "supper = np.ma.masked_where(t<upper,s)\n",
    "slower = np.ma.masked_where(t>lower,s)\n",
    "smiddle = np.ma.masked_where( (t<lower) | (t>upper),s)\n",
    "\n",
    "fig,ax = plt.subplots()\n",
    "ax.plot(t, smiddle, t, slower, t, supper)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "[Choosing Colormaps in Matplotlib](https://matplotlib.org/3.5.0/tutorials/colors/colormaps.html)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib import cm\n",
    "from colorspacious import cspace_converter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = [1,2,3,4,5,6,7,8,9,10,11]\n",
    "y = [1,1,1,1,1,1,1,1,1,1,1]\n",
    "colors = [1,2,3,4,5,6,7,8,9,10,100]\n",
    "\n",
    "plt.scatter(x,y,s=200,c=colors,cmap=plt.cm.get_cmap('cool',3))\n",
    "plt.clim(0,10)\n",
    "cbar = plt.colorbar(orientation='vertical', extend='both',pad=0.05,shrink=0.5,aspect=10,format='%.3f')\n",
    "cbar.set_label('Concentrations',size =15)\n",
    "cbar.set_ticks([0,5,10])\n",
    "cbar.set_ticklabels(['0grams','5m','cats'])\n",
    "cbar.ax.tick_params(labelsize =20)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "x = np.linspace(0, 10, 1000)\n",
    "I = np.sin(x) * np.cos(x[:, np.newaxis])\n",
    "plt.imshow(I)\n",
    "plt.colorbar()\n",
    "# t = pd.DataFrame(I)\n",
    "# t.describe()"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "3bff32627b040b5332bfbac7c51eea20a1271f1ac89d6a073d6e35a36c43d0c5"
  },
  "kernelspec": {
   "display_name": "Python 3.8.3 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
